package org.dja.nzw.discovery.zookeeper.client;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * Created by shuyun on 2016/7/6.
 */
public class ClientFactory {
    public static CuratorFramework create(String serverHosts) {
        CuratorFramework client = CuratorFrameworkFactory
                .builder()
                .connectString(serverHosts)
                .connectionTimeoutMs(5000)
                .sessionTimeoutMs(5000)
                .retryPolicy(new ExponentialBackoffRetry(1000, Integer.MAX_VALUE))
                .build();

        return client;
    }

    public static void destroy(CuratorFramework client) {
        if(null != client) {
            client.close();
        }
    }
}
